using System;
using System.Collections.Generic;
using System.Linq;
using converter.template.item;
using SsrsConverter;

namespace converter.template
{
    public sealed class Template
    {
        public List<TemplateItem> Body
        {
            get
            {
                return body;
            }
        }

        public List<Variable> Variables
        {
            get
            {
                return variables;
            }
        }

		// Gets a list of template datasources.
        public Dictionary<string, DataSource>.ValueCollection DataSources
        {
            get
            {
                return dataSources.Values;
            }
        }

        public Dictionary<string, DataSet> DataSets
        {
            get
            {
                return dataSets;
            }
        }

        /// <summary>
        /// Adds a new image to the list.
        /// </summary>
        /// <param name="image">An image to add.</param>
        public void AddEmbeddedImage(EmbeddedImage image)
        {
            if (!imageList.ContainsKey(image.GetName()))
                imageList[image.GetName()] = image;
        }

		// Returns an image by its name or null if an image is not there.
        public EmbeddedImage GetEmbeddedImage(string name)
        {
            if (imageList.ContainsKey(name))
                return imageList[name];
            else
                return null;
        }

		// Adds a datasource to the list.
		public void AddDataSource(DataSource ds)
		{
			if (!dataSources.ContainsKey(ds.GetName()))
				dataSources.Add(ds.GetName(), ds);
		}

        private readonly List<TemplateItem> body = new List<TemplateItem>();
        private readonly List<Variable> variables = new List<Variable>();
        private readonly Dictionary<string, DataSet> dataSets = new Dictionary<string, DataSet>();

        // A list of embedded images from an .rdl file.
        private Dictionary<string, EmbeddedImage> imageList = new Dictionary<string, EmbeddedImage>();
		// A list of datasources from an .rdl file and supplied .rds files.
        private Dictionary<string, DataSource> dataSources = new Dictionary<string, DataSource>();
    }
}
